<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page language="java" import="java.lang.*" %>
<%@ page import = "java.sql.SQLException" %>
<%@ page import = "com.seniorproject.aims.*" %>
<%@ page import = "java.util.List" %>
<%@page import="java.util.ArrayList"%>
<%@ page import = "java.util.Properties" %>
<%@ page import = "javax.servlet.ServletContext" %>
<%@ page import = "java.io.File" %>
<%@ page import = "java.io.InputStream" %>


<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Lecturer Edit Personal Info</title>
	
	<link rel="stylesheet" type="text/css" href="css/stylev2.css" />
	<link rel="stylesheet" type="text/css" href="css/frame2.css" />
	<link rel="stylesheet" type="text/css" href="css/student-system.css" />
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
	<script src="js/jquery.ajaxfileupload.js"></script>
	
	<style type="text/css">
		a {
	      text-decoration:none;
	   }
	</style>
	
<script>
	$(document).ready(function() {
		var patt = new RegExp("[#$%^*?!~`<>]");
		var src_path_full="null";
		
		$('input[type="file"]').ajaxfileupload({
			'action' : 'UploadServletStudentAddNormal',
			'onComplete' : function(response) {
				$('#upload').hide();
				$('#message').show();
				
				var statusVal = JSON.stringify(response.status);
	
				if(statusVal == "false")
				{
					$("#message").html("<font color='red'>"+ JSON.stringify(response.message) +" </font>");
					
				}	
				if(statusVal == "true")
				{
					 var xmlhttp;
						
						if(window.XMLHttpRequest) {
							// code for IE7+, Firefox, Chrome, Opera, Safari
							xmlhttp = new XMLHttpRequest();
						}
						else {
							// code for IE6, IE5
							xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
						}
						
						xmlhttp.onreadystatechange = function() {
							if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {	
								
								//alert("Back from lecturer_edit_personal_get_photo_temp:");
									
								src_path_full = xmlhttp.responseText;
								//alert("src_path_full:"+src_path_full);
								var src_path_temp = src_path_full.split("/");
								var length = src_path_temp.length;
								
								var src_path_a = src_path_temp[length-2];
								var src_path_b = src_path_temp[length-1];
								
								var src_path = src_path_a+"/"+src_path_b;
								
								$("#student_image").attr('src',src_path);
								$("#message").html("<font color='green'>"+ JSON.stringify(response.message) +" </font>");		
										
							
							}// end if check state
						
						}// end function						
						xmlhttp.open("POST", "student_edit_personal_get_photo_temp.jsp", true);
						xmlhttp.send();
				}			
			},
			'onStart' : function() {
				$('#upload').show();
				$('#message').hide();
			}
		});

		$('#save').click(function(){
			
			//alert("Save Active");
			var index = "<%=request.getParameter("index")%>";
			 var check = "";
			 var error = "กรุณากรอก";
			 //////////////////////////////////////////////////////////////
		     var title = document.getElementsByName('title');
			 var title_value;
			 
			 for(var i = 0; i < title.length; i++){
			    if(title[i].checked){
			        title_value = title[i].value;
			    }
			 }
		    
			if(title_value==null)
			{
				error = error + " คำนำหน้า";
				check="X";
			
			}
			else if (title_value=="etc")
			{
				title_value =  $('#title_etc').val();
				//alert("title etc   "+title_value);/////////////try//////////////////////////////////
					if(title_value==null){
						
							error = error + " คำนำหน้าแบบกำหนดเอง";
							check="X";
							
					} 
					
			}
			//////////////////////////////////////////////////////////////
			var name_th = document.getElementById('name');
			var name_th_value = name_th.value;
			if(name_th_value=="")
			{
				error = error + " ชื่อภาษาไทย";	
				check="X";
			}
			if(patt.test(name_th_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			//////////////////////////////////////////////////////////////
			var status = document.getElementById('status');
			var status_value = status.value;
			if(status_value=="")
			{
				error = error + " สถานะ";	
				check="X";
			}
			//////////////////////////////////////////////////////////////
			 
			var surname_th = document.getElementById('surname');
			var surname_th_value = surname_th.value;
			if(surname_th_value=="")
			{
				error = error + " นามสกุลภาษาไทย";	
				check="X";
			}
			if(patt.test(surname_th_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			
			 //////////////////////////////////////////////////////////////
			var gender = document.getElementsByName('gender');
			var gender_value;
			
			 for(var j = 0; j < gender.length; j++){
				    if(gender[j].checked){
				        gender_value = gender[j].value;
				    }
				 }
		
			 if(gender_value==null)
			 {
				 error = error + " เพศ";
				 check="X";
			 }
			
			//////////////////////////////////////////////////////////////
			
			 var date_of_birth = document.getElementById('date_of_birth');
			 var date_of_birth_value = date_of_birth.value; 
			 
			 if(date_of_birth_value=="")
			 {
				 error = error + " วันเกิด";
				 check="X";
			 }
			 //////////////////////////////////////////////////////////////
		 	 var select_department = document.getElementById('department');
			 var department_value = select_department.options[select_department.selectedIndex].value;
			 if(department_value=="select")
			{
				 error = error + "ภาควิชา";
				 check = "X";
			}
			//////////////////////////////////////////////
			////////finally Check ///////////
			if(error!="กรุณากรอก"){
					alert(""+error+"");
			}
			else{
			//	alert(":"+error+":");
			}
			////////////////// get data///////////////////
			
			var personal_id = document.getElementById('personalId');
 			var	 personal_id_value = personal_id.value;
 			if(patt.test(personal_id_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
 				 
			var name_en = document.getElementById('name_en');
			var name_en_value = name_en.value;
			if(patt.test(name_en_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			var surname_en = document.getElementById('surname_en');
			var surname_en_value = surname_en.value;
			if(patt.test(surname_en_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			
			
			
			
		     var marital_status = document.getElementsByName('marital_status');
			 var marital_status_value = null;
			 
			 for(var i = 0; i < marital_status.length; i++){
			    if(marital_status[i].checked){
			        marital_status_value = marital_status[i].value;
			    }
			 }
			 
			 
			var address = document.getElementById('address');
			var address_value = address.value;

			if(patt.test(address_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			
			var tel = document.getElementById('phonenumber');
			var tel_value = tel.value;
			if(patt.test(tel_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			var patt_email = new RegExp("[#$%^*?!~`<>]");
			var email = document.getElementById('email');
			var email_value = email.value;
			if(patt_email.test(email_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			
			var facebook = document.getElementById('facebook');
			var facebook_value = facebook.value;
			if(patt.test(facebook_value)) { 
				
				check="X";
				error = error +"กรุณาหลีกเลี่ยงอักขะพิเศษ";
			}
			
			var picture_value = src_path_full;
			
			 var select_edu_pos = document.getElementById('edupos');
			 var edu_pos_value = select_edu_pos.options[select_edu_pos.selectedIndex].value;
			 
			 var select_manage_pos = document.getElementById('manpos');
			 var manage_pos_value = select_manage_pos.options[select_manage_pos.selectedIndex].value;
			
			 //////////////////END GET DATA //////////////////
			//	alert("check:"+check);
			
			if(check=="")
			{
				/* AJAX */
				var xmlhttp;
				
				if(window.XMLHttpRequest) {
					// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
				else {
					// code for IE6, IE5
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {									
					
						//alert("I'm back");
						var result = xmlhttp.responseText;
						//alert("result:"+result);
						if(result=="fail"){
							alert("บันทึกข้อมูลไม่สำเร็จกรุณาตรวจสอบข้อมูล");
							
						}
						else if(result=="success"){
							alert("บันทึกข้อมูลสำเร็จ");
							window.location="/AIMS_Project/admin_lecturer.jsp";
							// redirect
							
						}else{
							alert("บันทึกข้อมูลไม่สำเร็จ");
							
						}
						
						//document.location.href = "admin_account.jsp";
					}
				}
				
				var parameter = "personal_id="+personal_id_value+
								"&title_th="+title_value+
							    "&name_th="+name_th_value+
							    "&surname_th="+surname_th_value+
							    "&name_en="+name_en_value+
								"&surname_en="+surname_en_value+
								"&gender="+gender_value+
								"&marital_status="+marital_status_value+
								"&date_of_birth="+date_of_birth_value+
								"&address="+address_value+
								"&tel="+tel_value+
								"&email="+email_value+
								"&facebook="+facebook_value+
								"&picture="+picture_value+
								"&department_id="+department_value+
								"&edu_pos="+edu_pos_value+
								"&manage_pos="+manage_pos_value+
								"&index="+index+
								"&status="+status_value;
				
				//alert(parameter);
				xmlhttp.open("POST", "admin_lecturer_edit_personal_save.jsp?"+parameter, true);
				xmlhttp.send();
			}else{
				
				alert("กรุณาตรวจสอบความถูกต้องอีกครั้ง");
				
			}
			
		});
		
	});
	
	// check title etc was click
	function click_title_etc() {
		document.getElementById('title_etc').readOnly = false;
		$('#title_etc').focus();
	}
	
	function click_title() {
		document.getElementById('title_etc').readOnly = true;
	}
	

</script>
</head>
<body>
<%
	// get session
	String strUser = String.valueOf(session.getAttribute("sUser"));
	HttpSession htp_session = request.getSession();
	
	// check session
		if (htp_session == null || htp_session.getAttribute("sUser") == null) {
		    // Forward the control to login.jsp if authentication fails or session expires
		    request.getRequestDispatcher("/login.jsp").forward(request,
		        response);
		}
		if(!"admin".equals(htp_session.getAttribute("sUser"))){%>
			<script>alert("This user dont have PERMISSION to access this zone.");</script>
			<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=system_select.jsp"> 	
	<%}
	
	
	//set Database Connection
	String hostProps = "";
	String usernameProps  = "";
	String passwordProps  = "";
	String databaseProps = "";
	
	try {
		//get current path
		ServletContext servletContext = request.getSession().getServletContext();
		
		InputStream input = servletContext.getResourceAsStream("/properties/connectDB.properties");
		Properties props = new Properties();
		
		props.load(input);

		hostProps  = props.getProperty("host");
		usernameProps  = props.getProperty("username");
		passwordProps  = props.getProperty("password");
		databaseProps = props.getProperty("database");
	} catch (Exception e) { 
		out.println(e);  
	}
	
	// connect database
	Connection connect = null;		
	try {
		Class.forName("com.mysql.jdbc.Driver");
	
		connect =  DriverManager.getConnection("jdbc:mysql://" + hostProps  + "/" + databaseProps +
				"?user=" + usernameProps  + "&password=" + passwordProps );
	
		if(connect != null){
			System.out.println("Database Connect Sucesses.");
		} else {
			System.out.println("Database Connect Failed.");	
		}

	} catch (Exception e) {
		out.println(e.getMessage());
		e.printStackTrace();
	}
	
	System.out.println("@admin_lecturer_edit_personal");
	
	
	
	
	/* find department in database */
	List<Department> department = new ArrayList<Department>();
	int departmentIdOld =0;
	String departmentNameOld="";
	
	try {			   
		ResultSet rs_department = connect.createStatement().executeQuery("SELECT department_id, department_name_th " 
				+ " FROM department " + " ORDER BY department_id");
		
		while(rs_department.next()) {
			Department dep = new Department();
			
			dep.setDepartmentNameTH(rs_department.getString("department_name_th"));
			dep.setDepartmentId(Integer.parseInt(rs_department.getString("department_id")));
			
			department.add(dep);
		}
		
	} catch (SQLException e) {
		e.printStackTrace();
	}
	
	List<EduPos> edupos = new ArrayList<EduPos>();
	String edupos_id_old = "";
	String edupos_name_old = "";
	try{
		ResultSet rs_edu = connect.createStatement().executeQuery("SELECT * " 
				+ " FROM education_position " + " ORDER BY education_position_id");
		while(rs_edu.next()){

			EduPos temp = new EduPos();
			
			temp.setEduPosId(rs_edu.getString("education_position_id"));
			temp.setEduPosName(rs_edu.getString("education_position_name"));
			
			edupos.add(temp);
		}
		
	}catch(Exception ro){
		
		ro.printStackTrace();
	}
	//////////////////////////////////////////////////////////////
	List<ManagePos> manpos = new ArrayList<ManagePos>();
	List<ManagePos> manpos2 = new ArrayList<ManagePos>();
	String manpos_id_old = "";
	String manpos_name_old = "";
	try{
		ResultSet rs_man = connect.createStatement().executeQuery("SELECT * " 
				+ " FROM management_position " + " ORDER BY management_position_id");
		while(rs_man.next()){

			

			ManagePos temp = new ManagePos();
			ManagePos temp2= new ManagePos();
			
			temp.setManagePosId(rs_man.getString("management_position_id"));
			temp.setManagePosName(rs_man.getString("management_position_name"));
			
			
			temp2.setManagePosId(rs_man.getString("management_position_id"));
			temp2.setManagePosName(rs_man.getString("management_position_name"));
			
			
			manpos.add(temp);
			manpos2.add(temp2);
		}
	System.out.println("manpos.size():"+manpos.size());
		
	}catch(Exception ro){
		
		ro.printStackTrace();
	}
	
	
	
	
	String index = request.getParameter("index");
	
	System.out.println("lecturer_index  "+index);//////try//////
	
	if(index==null)
	{
		 response.sendRedirect("admin_lecturer.jsp");
	}
	
	System.out.println("@ lecturer_edit_persoanl index:"+index);
				
	
	
	
	Lecturer lec = new Lecturer();
	
	String title_th = "";
	String title_en = "";
	
	
	String sql_cmd =" SELECT L.education_position_id,  L.picture ,L.status ,L.department_id, N.title_th,N.title_en, "+
			" N.name_th, N.surname_th , N.name_en , N.surname_en ,P.personal_id, P.gender,P.marital_status ,"+
			" P.address , P.phone_number, P.email , P.facebook ,P.date_of_birth ,"+
			" L.management_position_id, E.education_position_name , D.department_name_th"+
			" FROM lecturer L , full_name N , department D ,people P  , education_position E "+
			" WHERE L.index = P.index AND P.full_name_id = N.full_name_id " +
			" AND L.department_id = D.department_id "+
			" AND L.education_position_id = E.education_position_id "+
			" AND L.index = '"+index+"'";
	
	System.out.println("sql_cmd:"+sql_cmd);
	
	ResultSet rs = 
			connect.createStatement().executeQuery(" SELECT L.education_position_id,  L.picture ,L.status ,L.department_id, N.title_th,N.title_en, "+
			" N.name_th, N.surname_th , N.name_en , N.surname_en ,P.personal_id, P.gender,P.marital_status ,"+
			" P.address , P.phone_number, P.email , P.facebook ,P.date_of_birth ,"+
			" L.management_position_id, E.education_position_name , D.department_name_th"+
			" FROM lecturer L , full_name N , department D ,people P  , education_position E "+
			" WHERE L.index = P.index AND P.full_name_id = N.full_name_id " +
			" AND L.department_id = D.department_id "+
			" AND L.education_position_id = E.education_position_id "+
			" AND L.index = '"+index+"'");
	
	while(rs.next())
	{
		System.out.println("Found Result");		
		departmentIdOld = Integer.parseInt(rs.getString("department_id"));
		departmentNameOld = rs.getString("department_name_th");
				
		
		String src_path_full = rs.getString("picture");
		System.out.println("src_path_full:"+src_path_full);
	//	System.out.println(src_path_full.equals("null"));
	//	System.out.println(!("null").equals(src_path_full));
	//	System.out.print((src_path_full!=null)||(!("null").equals(src_path_full)));
		
		if((src_path_full!=null)&&(!("null").equals(src_path_full)))
		{
			String[] src_path_temp = src_path_full.split("/");	
			int length = src_path_temp.length;
			
			String src_path_a = src_path_temp[length-2];
			String src_path_b = src_path_temp[length-1];
			
			String src_path = src_path_a+"/"+src_path_b;
			
			lec.setPicture(src_path);
		
		}else{
			lec.setPicture("upload/default_person_icon.jpg");
			
		}
		
		
		
		if(rs.getString("personal_id")==null || "null".equals(rs.getString("personal_id")))
		{
			lec.setPersonalId("");
		}	
		else{
			lec.setPersonalId(rs.getString("personal_id"));
		}
		
		
		
		System.out.println("title_th:"+rs.getString("title_th"));
		if(rs.getString("title_th")==null || "null".equals(rs.getString("title_th")))
		{
			lec.setTitleTH("");	
		}else{
			lec.setTitleTH(rs.getString("title_th"));
		}
		
		if(rs.getString("title_en")==null || "null".equals(rs.getString("title_en")))
		{
			lec.setTitleEN("");	
		}else{
			lec.setTitleEN(rs.getString("title_en"));
		}
		
		
		lec.setNameTH(rs.getString("name_th"));
		lec.setSurnameTH(rs.getString("surname_th"));
		
		
		if(rs.getString("name_en")==null || "null".equals(rs.getString("name_en")))
		{
			lec.setNameEN("");
		}else{
			lec.setNameEN(rs.getString("name_en"));
		}
		
	
		if(rs.getString("surname_en")==null || "null".equals(rs.getString("surname_en")))
		{
			lec.setSurnameEN("");
		}else{
			lec.setSurnameEN(rs.getString("surname_en"));
		}
		
		if(rs.getString("date_of_birth")==null || "null".equals(rs.getString("date_of_birth")))
		{
			lec.setBirtgdate("");
		}else{
			lec.setBirtgdate(rs.getString("date_of_birth"));				
		}
	
					
		if(rs.getString("gender").equals("M"))
		{
			lec.setGender("ชาย");
		}else
		{
			lec.setGender("หญิง");
		}
		
		System.out.println("marital_status:"+rs.getString("marital_status"));
		if(rs.getString("marital_status")==null || "null".equals(rs.getString("marital_status")))
		{
			lec.setMaritalStatus("");
			
		}else{
			lec.setMaritalStatus(rs.getString("marital_status"));
		}
			
		
		if(rs.getString("address")==null || "null".equals(rs.getString("address")))
		{
			lec.setAddress("");
		}else{
			lec.setAddress(rs.getString("address"));
		}
		if(rs.getString("phone_number")==null || "null".equals(rs.getString("phone_number")))
		{
			lec.setTelephone("");
		}else{
			lec.setTelephone(rs.getString("phone_number"));
		}
		if(rs.getString("email")==null || "null".equals(rs.getString("email")))
		{
			lec.setEmail("");
		}else{
			lec.setEmail(rs.getString("email"));
		}
		if(rs.getString("status")==null || "null".equals(rs.getString("status")))
		{
			lec.setStatus("");
		}else{
			lec.setStatus(rs.getString("status"));
		}
		if(rs.getString("facebook")==null|| "null".equals(rs.getString("facebook")))
		{
			lec.setFacebook("");
		}else{
			lec.setFacebook(rs.getString("facebook"));
		}
		
		lec.setDepartment(rs.getString("department_name_th"));
		
		
		lec.setEducationPosition(rs.getString("education_position_name"));
		edupos_id_old = rs.getString("education_position_id");
		edupos_name_old = rs.getString("education_position_name");
			
		
		title_th = rs.getString("title_th");	
		title_en = rs.getString("title_en");	
		
		
		String temp_man_pos = rs.getString("management_position_id");		
		if(("").equals(rs.getString("management_position_id"))){
			
			lec.setManagementPosition("");
			
		}else{
			
			String sql = " SELECT * "+
					  " FROM management_position "+
					  " WHERE management_position_id='"+temp_man_pos+"'";
			System.out.println("SQL M P "+sql);
			
			ResultSet rs_man = connect.createStatement().executeQuery(" SELECT * "+
																	  " FROM management_position "+
																	  " WHERE management_position_id='"+temp_man_pos+"'");
					
			while(rs_man.next()){
			
				
				lec.setManagementPosition(rs_man.getString("management_position_name"));
				manpos_id_old = rs_man.getString("management_position_id");
				manpos_name_old = rs_man.getString("management_position_name");
				
			}
					
			
		}
		
	}
	
	connect.close();
	
	System.out.println("End Jsp");
	
	
	
	
%>

	<div id="page-wrap">
		<div id="inside">
			<table border="0">
				<tr style="font-size:24px">
					<td width="600" height="100" style= "background-color: #273b80;border: 0px ;padding: 0px; 0px;" >
						<div id="header_banner-2"></div>
					</td>
					
					<td width="680" height="100" style= "background-color: #273b80;border: 0px;padding: 0px; 0px;" >
						<p align="right"><label><font size="4" color="#ffffff">username : <%=strUser%>&nbsp;&nbsp;</font></label></p>
						<a href="logout.jsp"><p align="right"><label style="cursor: pointer;"><font size="3" color="#ffffff">log out &nbsp;</font></label></p></a>
					</td>
				</tr>
			</table> 
				
				<div id="main-content-ac">
						
						<div class="imageFrame">อาจารย์ / แก้ไขข้อมูลส่วนตัว</div>
						
						<br/><br/><br/><br/><br/>
						<center>
							<table width="1200px" >								 
									  <tr style="font-size:20px">
										  		<td  width="50" height="50" rowspan="6" style="text-align: center;">
									        			
									        			<img id="student_image" src="<%=lec.getPicture() %>" style="width:130px;height:160px;	">
									       
									         			 <form>	
																<input type="file" name="file"/><br />
																<div id="upload" style="display: none;">Uploading..</div>
																<div id="message">
																</div>
														  </form>
									      
									      	  </td>
						        
						        	  </tr>
									  
								
									  <tr style="font-size:24px">
				        	
								                <td width="400" height="50">
								                	<font size="5"><strong>เลขประจำตัวประชาชน</strong></font>
								                </td>
								                <td width="600" height="50">
								                	<input type="text" id="personalId" name="personalId" style="font-size:18px" value="<%=lec.getPersonalId() %>"/>
								         		
								                </td>
				                	      
				         			 </tr>
								 
									 <tr style="font-size:24px">
											<input type="hidden" name="title_old" value="<%=lec.getTitleEN()%>">
								                <td height="50">
								                	<font size="5"><strong>คำนำหน้า</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								   <%
								   				if("Mr.".equals(lec.getTitleEN()) || "นาย".equals(title_th)) {
								   					System.out.println("MR");////////////////////////////try////////////////////////
								   %>             	
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" checked="checked"  onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                       
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
								                      </label>
									<%
								   				}
								   				else if("Mrs.".equals(lec.getTitleEN()) || "นาง".equals(title_th)) {
								   					System.out.println("MRS");////////////////////////////try////////////////////////
									%>
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" checked="checked" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                        
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly"/>
								                      </label>
								    <%
								   				}
								   				else if("Miss".equals(lec.getTitleEN()) || "นางสาว".equals(title_th)) {
								   					System.out.println("MISS");////////////////////////////try////////////////////////
								    %>
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" checked="checked" onclick="click_title()" />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                       
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" readonly="readonly" />
								                      </label>
								    <%
								   				}
								   				else {
								   					System.out.println("NO");////////////////////////////try////////////////////////
								    %>	
												 	  <label>
								                        <input type="radio" name="title" id="title" value="นาย" id="mr" onclick="click_title()" />
								                        <font size="5">นาย</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นาง" id="mrs" onclick="click_title()" />
								                        <font size="5">นาง</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="นางสาว" id="miss" onclick="click_title()"  />
								                        <font size="5">นางสาว</font>
								                      </label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="title" id="title" value="etc" id="etc" checked="checked"  onclick="click_title_etc()" />
								                        <font size="5">อื่นๆ</font>
								                        
								                        <input type="text"  style="font-size:18px" size="10" id="title_etc" name="title_etc" value="<%=lec.getTitleTH()%>" />
								                      </label>
								    <%
								   				}
								    %>	                      
								                </td>
								      </tr>
									  
									  <tr style="font-size:24px">
								            <input type="hidden" name="name_old" value="<%=lec.getNameTH()%>">
								                <td height="50">
								                	<font size="5"><strong>ชื่อ</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								                	<input name="name" id="name" type="text" style="font-size:18px" value="<%=lec.getNameTH() %>"/>
								        	        </td>
				         			   </tr>
									  
									   <tr style="font-size:24px">
							        		    <input type="hidden" name="surname_old" value="<%=lec.getSurnameTH()%>">
							                <td height="50">
							                	<font size="5"><strong>นามสกุล</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
							                </td>
							                <td height="50">
							                	<input name="surname" id="surname" type="text" style="font-size:18px" value="<%=lec.getSurnameTH() %>" />
							                </td>
					                
				          			  </tr>
				            
									  
									
									  
									  <tr style="font-size:24px">
							            <input type="hidden" name="name_en_old" value="<%=lec.getNameEN()%>">
							                <td height="50">
							                	<font size="5"><strong>ชื่อ(ภาษาอังกฤษ)</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
							                </td>
							                <td height="50">
							                	<input name="name_en" id="name_en" type="text" style="font-size:18px" value="<%=lec.getNameEN() %>" />
							                </td>
				       			     </tr>
									  
									   <tr style="font-size:24px">
								            <input type="hidden" name="surname_en_old" value="<%=lec.getSurnameEN()%>">				            
								             	<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>นามสกุล(ภาษาอังกฤษ)</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								                	<input name="surname_en" id="surname_en" type="text" style="font-size:18px" value="<%=lec.getSurnameEN() %>" />
								                </td>
				        		     </tr>
									  
									  <tr style="font-size:24px">
								            <input type="hidden" name="gender_old" value="<%=lec.getGender()%>">	
												<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>เพศ</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
								                </td>
								                <td height="50">
								   
								    <%
								    				if("ชาย".equals(lec.getGender())) {
								    %>
								   					 <label>
								                        <input type="radio" name="gender" value="M" id="man" checked="checked" />
								                        <font size="5">ชาย</font></label>
								                        
								                        &nbsp;&nbsp;
								                      
								                      <label>
								                        <input type="radio" name="gender" value="F" id="women" />
								                        <font size="5">หญิง</font></label>
								    <%
								    				}
								    				else {
								    %>
								    					<input type="radio" name="gender" value="M" id="man" />
								                        <font size="5">ชาย</font></label>
								    		                        
								                        &nbsp;&nbsp;
								                      
								                      <label>
								                        <input type="radio" name="gender" value="F" id="women" checked="checked" />
								                        <font size="5">หญิง</font></label>
								    <%					
								    				}
								    %>
								                      
								                </td>
								       </tr>
									  
									   <tr style="font-size:24px">
								             <input type="hidden" name="marital_status_old" value="<%=lec.getMaritalStatus()%>">	
								             	<td  width="400" height="50"></td>
								                <td height="50">
								                	<font size="5"><strong>สถานภาพ</strong></font>
								                </td>
								                <td height="50">
								   <%
								   			if("โสด".equals(lec.getMaritalStatus())) {
								   %>
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" checked="checked" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
								                        <font size="5">หย่าร้าง</font></label>
								   <%
								   			}
								   			else if("แต่งงาน".equals(lec.getMaritalStatus())) {
								   %>               
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" checked="checked" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
								                        <font size="5">หย่าร้าง</font></label>		
								   <%
								   			}
								   			else if("หย่าร้าง".equals(lec.getMaritalStatus())) {
								   %>                    
								   		                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" checked="checked" />
								                        <font size="5">หย่าร้าง</font></label>		
								   <%
								   			}
								   			else {
									%>                    
								   		                <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="โสด" />
								                        <font size="5">โสด</font></label>
								                      &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status"id="marital_status" value="แต่งงาน" />
								                        <font size="5">แต่งงาน</font></label>
								                          &nbsp;&nbsp;
								                      <label>
								                        <input type="radio" name="marital_status" id="marital_status" value="หย่าร้าง" />
								                        <font size="5">หย่าร้าง</font></label>		
								   <%				
								   			}
								   %>                    
								                </td>
							           </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">วัน/เดือน/ปีเกิด</font></td>
										<td height="50">
												   <input type="date" id="date_of_birth" name="date_of_birth" style="font-size: 18px;" value="<%=lec.getBirtgdate() %>"/>
										</td>           
									  </tr>										  
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">ที่อยู่</font></td>
										<td height="50">
											<textarea name="address" id="address" cols="50" rows="3" style="font-size: 18px;"> <%=lec.getAddress() %> </textarea>
										</td>           
									  </tr>	
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">เบอร์โทรศัพท์</font></td>
												
										<td height="50">
												<input name="phonenumber" id="phonenumber" type="text" style="font-size:18px" value="<%=lec.getTelephone()%>" />
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">อีเมลล์</font></td>
			
										<td height="50">
												<input name="email" id="email" type="text" style="font-size:18px" value="<%=lec.getEmail() %>" />								
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;"><font size="5">Facebook</font></td>
											
										<td height="50">
											<input name="facebook" id="facebook" type="text" style="font-size:18px" value="<%=lec.getFacebook() %>" />
										</td>           
									  </tr>
									  	  
									    <tr style="font-size:24px">
									    	<td  width="400" height="50"></td>
						            	<td height="50" width="250">
						                	<font size="5"><strong>ภาควิชา</strong></font>
						                			<label><font size="5" color="#FF0000">*</font></label>
						                </td>
						              	
						              	<input type="hidden" name="departmentId" id="departmentId" value="<%=departmentIdOld %>" />
						              	<input type="hidden" name="departmentName" id="departmentName" value="<%=departmentNameOld %>" />
						              	<td height="50">
						                	<select name="department" id="department" style="font-size: 18px;">
							                	<option value="<%=departmentIdOld %>"><%=departmentNameOld %></option>
<%
												for(Department dept : department) {
													if(departmentIdOld == dept.getDepartmentId()) {
														
													}
													else {
%>
														<option value="<%=dept.getDepartmentId()%>" id="<%=dept.getDepartmentId()%>"><%=dept.getDepartmentNameTH()%></option>	
<%												
													}
												}
%>
							                </select>
							        	</td>
						            </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;">
												<font size="5">ตำแหน่งทางการศึกษา</font>
						                			<label><font size="5" color="#FF0000">*</font></label>
						                </td>
											<input type="hidden" name="edupos_id_old" id="edupos_id_old" value="<%=edupos_id_old %>" />
						              		<input type="hidden" name="edupos_name_old" id="edupos_name_old" value="<%=edupos_name_old %>" />		
										<td height="50">
											<select name="edupos" id="edupos" style="font-size: 18px;">
							                	<option value="<%=edupos_id_old %>"><%=edupos_name_old %></option>
<%
												for(EduPos edu_temp : edupos) {
													if(edupos_id_old == edu_temp.getEduPosId()) {
														
													}
													else {
%>
														<option value="<%=edu_temp.getEduPosId()%>" id="<%=edu_temp.getEduPosId()%>"><%=edu_temp.getEduPosName()%></option>	
<%												
													}
												}
%>
											</select>
										</td>           
									  </tr>
									  
									   <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;">
												<font size="5">ตำแหน่งบริหาร</font>
						                			<label><font size="5" color="#FF0000">*</font></label>
						                </td>
											<input type="hidden" name="manpos_id_old" id="manpos_id_old" value="<%=manpos_id_old %>" />
						              		<input type="hidden" name="manpos_name_old" id="manpos_name_old" value="<%=manpos_name_old %>" />		
										<td height="50">
												<select name="manpos" id="manpos" style="font-size: 18px;">
											<%
												if(("").equals(manpos_id_old))
												{
													
											%>		
													<option value="no" id="no_manpos_option">ไม่มี</option>
											<% 
													for(ManagePos man_temp2 : manpos2){
													
											%>
													<option value="<%=man_temp2.getManagePosId()%>" id="<%=man_temp2.getManagePosId()%>"><%=man_temp2.getManagePosName()%></option>	
											<%
													}
												}
												else{
													for(ManagePos man_temp : manpos) {
														if(manpos_id_old == man_temp.getManagePosId()) {
															
														}
														else {
											%>
														<option value="<%=man_temp.getManagePosId()%>" id="<%=man_temp.getManagePosId()%>"><%=man_temp.getManagePosName()%></option>	
											<%
													}
												}
											}
											 %>
											 </select>
										</td>           
									  </tr>
									  
									  <tr style="font-size:20px">
									  	<td  width="400" height="50"></td>
										<td height="50" style="font-weight: bold;">
											<font size="5">สถานะ</font>
						                			<label><font size="5" color="#FF0000">*</font></label>
						                </td>
										
										<td height="50">	
											<select name="status" id="status" style="font-size: 18px;">
													<option value="<%=lec.getStatus()%>"><%=lec.getStatus()%></option>
								<%
												if("ปกติ".equals(lec.getStatus())) { }
												else {
								%>
													<option value="ปกติ">ปกติ</option>
								<%
												}
												if("ลาออก".equals(lec.getStatus())) { }
												else {
								%>
													<option value="ลาออก">ลาออก</option>
								<%
												}
												if("อื่นๆ".equals(lec.getStatus())) { }
												else {
								%>
													<option value="อื่นๆ">อื่นๆ</option>
								<%
												}
								%>
											</select>
												
										</td>           
									  </tr>
									  
									  <tr>
									  	<td></td>
						            	<td colspan="2">
						            		<label><font size="3" color="#FF0000">หมายเหตุ: * คือ ข้อมูลสำคัญ จำเป็นต้องกรอก</font></label>
						            	</td>
						            </tr>
									  
									  <tr style="font-size:20px">
									 	<td  width="400" height="50"></td>
									  	<td height="50">
									  		<input type="button" name="save" id="save"  value="บันทึก" class="buttonStyle"/>
										
									  	</td>
									  	<td height="50">
									  		<a href="admin_lecturer.jsp"><button class="buttonStyle">ยกเลิก</button></a></center>
										
									  	</td>										          
									  </tr>
								</table>
						</center>
						
						<br><br><br>
				
			<div style="clear: both;"></div>
				
			<div id="footer"></div>
			
		</div>		
			<div style="clear: both;"></div>		
   </div>


</body>
</html>